package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Dictionary;
import cn.wolfcode.crm.domain.DictionaryItem;
import cn.wolfcode.crm.mapper.DictionaryItemMapper;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.DictionaryItemQueryObject;
import cn.wolfcode.crm.service.IDictionaryItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DictionaryItemServiceImpl implements IDictionaryItemService {
    @Autowired
    private DictionaryItemMapper dictionaryItemMapper;


    public int deleteByPrimaryKey(Long id) {
        return dictionaryItemMapper.deleteByPrimaryKey(id);
    }

    public int insert(DictionaryItem dictionaryitem) {
        return dictionaryItemMapper.insert(dictionaryitem);
    }

    public List<Dictionary> selectAll() {
        return dictionaryItemMapper.selectAll();
    }

    public int updateByPrimaryKey(DictionaryItem dictionaryitem) {
        return dictionaryItemMapper.updateByPrimaryKey(dictionaryitem);
    }

    public PageResult query(DictionaryItemQueryObject qo) {
        if (dictionaryItemMapper.queryForCount(qo) == 0)
            return new PageResult(Integer.valueOf(dictionaryItemMapper.queryForCount(qo)), Collections.emptyList());
        else
            return new PageResult(Integer.valueOf(dictionaryItemMapper.queryForCount(qo)), dictionaryItemMapper.queryForList(qo));
    }

    public List<Dictionary> select(DictionaryItemQueryObject qo) {
        return dictionaryItemMapper.selectByPrimaryKey(qo);
    }
}
